import emitter from "../utils/eventbus";
import * as d3 from "d3";
import d3DrawStore from "../store/modules/d3Draw";

/**
 * 
 * @param $ 
 * @param d3CanvasRef 
 * @param width 
 * @param heightStart 
 * @param heightEnd 
 */
export function initDrillPipe($: any, d3CanvasRef: any, width: number, Start: number, height: number) {
    let id: string = $.attr("id");
    const d3Canvas = d3CanvasRef;//画布信息
    const widthCenter = d3Canvas.offsetWidth / 2 //中心线
    const yScale = d3DrawStore().scale
    const start = yScale(Start)
    const end = yScale(height - Start)
    const dirllPipe = $.append("rect")
        .attr("x", widthCenter - width / 2)// 矩形左上角的 x 坐标
        .attr("y", start)  // 矩形左上角的 y 坐标
        .attr("width", width)  // 矩形的宽度
        .attr("height", end)  // 矩形的高度
        .attr("fill", "brown") // 填充颜色
        .attr("opacity", 0.2); // 43,147,123
    emitter.on(id, (transform: any) => {
        dirllPipe.attr("transform", transform);
    });

    return dirllPipe
}

export function updateDrillPipe(dirllPipe: any, d3CanvasRef: any, width: number, heightStart: number, heightEnd: number) {
    const widthCenter = d3CanvasRef.offsetWidth / 2 //中心线\
    const yScale = d3DrawStore().scale
    const start = yScale(heightStart)
    const end = yScale(heightEnd)
    dirllPipe.attr("x", widthCenter - width / 2)// 矩形左上角的 x 坐标
        .attr("y", start)  // 矩形左上角的 y 坐标
        .attr("width", width)  // 矩形的宽度
        .attr("height", end)  // 矩形的高度
        .attr("fill", "grey");  // 填充颜色
}

export function deleteDrillPipe(dirllPipe: any){
    dirllPipe.remove();
}